package cn.sll.base.service.impl.controller;

import cn.sll.base.service.VerifyCodeService;
import cn.sll.base.util.AjaxResult;
import cn.sll.org.dto.SmsDto;
import cn.sll.org.dto.SmsRegisterDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
        String imageCode = verifyCodeService.imageCode(imageCodeKey);
        return AjaxResult.me().setResultObj(imageCode);
    }

    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid SmsDto smsDto){
        verifyCodeService.smsCode(smsDto);
        return AjaxResult.me().success();
    }

    @PostMapping("/smsRegister")
    public AjaxResult smsRegister(@RequestBody @Valid SmsRegisterDto dto){
        verifyCodeService.smsRegister(dto);
        return AjaxResult.me().success();
    }

}
